package com.kelvin.oocl.crms.entity;

import com.kelvin.oocl.crms.util.Comparable;

/**
 * 客户实体类
 * @author MAIKE
 *
 */
public class Customer extends Comparable{
	private Integer id;
	private String name;
	private String sex;
	private String birthDate;
	private String address;
	private String phoneNumber;
	
	private int sort=0;  //0按id排序，1按name排序
	
	public Customer(Integer id, String name, String sex, String birthDate,
			String address, String phoneNumber) {
		super();
		this.id = id;
		this.name = name;
		this.sex = sex;
		this.birthDate = birthDate;
		this.address = address;
		this.phoneNumber = phoneNumber;
	}
	
	public Customer() {
	}
	
	public Customer(String name, String sex, String birthDate,
			String address, String phoneNumber) {
		super();
		this.name = name;
		this.sex = sex;
		this.birthDate = birthDate;
		this.address = address;
		this.phoneNumber = phoneNumber;
	}
	
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getSex() {
		return sex;
	}
	public void setSex(String sex) {
		this.sex = sex;
	}
	public String getBirthDate() {
		return birthDate;
	}
	public void setBirthDate(String birthDate) {
		this.birthDate = birthDate;
	}
	public String getAddress() {
		return address;
	}
	public void setAddress(String address) {
		this.address = address;
	}
	public String getPhoneNumber() {
		return phoneNumber;
	}
	public void setPhoneNumber(String phoneNumber) {
		this.phoneNumber = phoneNumber;
	}
	
	public int getSort() {
		return sort;
	}

	public void setSort(int sort) {
		this.sort = sort;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Customer other = (Customer) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "Customer [id=" + id + ", name=" + name + ", sex=" + sex
				+ ", birthDate=" + birthDate + ", address=" + address
				+ ", phoneNumber=" + phoneNumber + "]";
	}

	@Override
	public int compareTo(Object o) throws Exception{	//-1 比 o小，1比o大，0跟o相等
		if (o instanceof Customer) {
			Customer c = (Customer) o;
			if(this.sort==0){
				if(c.id==this.id){
					return 0;
				}else if(c.id<this.id){
					return 1;
				}else {
					return -1;
				}
			}else {
				return this.name.compareTo(c.getName());
			}
		}else {
			throw new Exception("Different type can not be compared");
		}
	}
}
